<template>
    <div>
        <van-nav-bar
      title="收货地址"
      left-text="返回"
      left-arrow
      @click-left="$router.go(-1)"
      
    />

    <van-address-list
    v-model="chosenAddressId"
    :list="list"
    default-tag-text="默认"
    @add="onAdd"
    @edit="onEdit"
    @select="sel"
    />
    </div>
</template>
<script>
import { Toast } from 'vant';
import {set,get} from "@/utils/local"
export default {
    components: {//注册组件
        
    },
    props: {},
    data() {
        return {
            chosenAddressId:'',
            list:[]
        };
    },
    computed: {
        
    },
    created() {//创建
        
    },
    mounted() {//挂载
        this.getList()
    },
    methods: {//方法
        getList(){// 获取收货地址列表
            this.list=get("addr")||[]
            this.chosenAddressId=this.list.find(v=>v.isDefault)?.id
        },
        onAdd() {
        // Toast('新增地址');
          this.$router.replace("/address")
        },
        onEdit(item, index) {
        Toast('编辑地址:' + index);
            this.$router.replace("/address?id="+item.id)
        },
        sel(item){
          console.log(item);
          this.list.map(v=>{
            v.isDefault=false
          })
          item.isDefault=true
          set("addr",this.list)
          
        }
    },
    watch: {
        
    },
};
</script>
<style scoped lang="less">
.van-button--danger{
    background:rgb(150, 191, 183);
    border:none;
}
</style>
